package com.dt.platform.generator.module.hr;


import com.dt.platform.constants.db.HrTables;
import com.dt.platform.constants.enums.common.StatusEnableEnum;
import com.dt.platform.constants.enums.common.YesNoEnum;
import com.dt.platform.constants.enums.hr.*;
import com.dt.platform.domain.hr.*;
import com.dt.platform.domain.hr.meta.*;
import com.dt.platform.generator.config.Config;
import com.dt.platform.hr.page.PaperPageController;
import com.dt.platform.proxy.hr.LearnPaperServiceProxy;
import com.dt.platform.proxy.hr.LearnServiceProxy;
import com.dt.platform.proxy.hr.PaperServiceProxy;
import com.dt.platform.proxy.hr.PersonServiceProxy;
import com.github.foxnic.generator.builder.view.config.DatePickerType;
import com.github.foxnic.generator.config.WriteMode;
import org.github.foxnic.web.domain.hrm.Employee;


public class APaperGtr extends BaseCodeGenerator {
    public APaperGtr() {
        super(HrTables.HR_PAPER.$TABLE,"811268060357853184");
    }

    public void generateCode() throws Exception {
        System.out.println(this.getClass().getName());


        cfg.getPoClassFile().addListProperty(PaperQuestion.class,"paperQuestionList","paperQuestionList","paperQuestionList");

        cfg.getPoClassFile().addListProperty(PaperQuestion.class,"PaperQuestionForJudgeList","PaperQuestionForJudgeList","PaperQuestionForJudgeList");
        cfg.getPoClassFile().addListProperty(PaperQuestion.class,"PaperQuestionForRadioList","PaperQuestionForRadioList","PaperQuestionForRadioList");
        cfg.getPoClassFile().addListProperty(PaperQuestion.class,"PaperQuestionForChoiceList","PaperQuestionForChoiceList","PaperQuestionForChoiceList");
        cfg.getPoClassFile().addListProperty(PaperQuestion.class,"PaperQuestionForTextAreaList","PaperQuestionForTextAreaList","PaperQuestionForTextAreaList");



        cfg.getPoClassFile().addSimpleProperty(Learn.class,"learn","learn","learn");
        cfg.getPoClassFile().addSimpleProperty(LearnPaper.class,"learnPaper","learnPaper","learnPaper");
        cfg.getPoClassFile().addListProperty(PaperQuestionRel.class,"paperQuestionRealList","paperQuestionRealList","paperQuestionRealList");
        cfg.getPoClassFile().addSimpleProperty(String.class,"selectedCode","selectedCode","selectedCode");


        cfg.view().field(HrTables.HR_PAPER.ID).basic().hidden(true);
        cfg.view().field(HrTables.HR_PAPER.NAME).search().fuzzySearch();

        cfg.view().field(HrTables.HR_PAPER.NAME).form().validate().required();
        cfg.view().field(HrTables.HR_PAPER.SDATE).form().validate().required().form().dateInput().type(DatePickerType.datetime).format("yyyy-MM-dd HH:mm:ss").defaultNow().search().range();
        cfg.view().field(HrTables.HR_PAPER.EDATE).form().validate().required().form().dateInput().type(DatePickerType.datetime).format("yyyy-MM-dd HH:mm:ss").defaultNow().search().range();
        cfg.view().field(HrTables.HR_PAPER.CREATE_TIME).search().range();
        cfg.view().search().inputLayout(
                new Object[]{
                        HrTables.HR_PAPER.IF_LEARN,
                        HrTables.HR_PAPER.MODE,
                        HrTables.HR_PAPER.NAME,
                        HrTables.HR_PAPER.CREATE_TIME,
                }
        );

        cfg.view().list().disableBatchDelete();

        cfg.view().field(HrTables.HR_PAPER.OWNER_CODE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.OWNER_ID).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.QUESTION_MODE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.UPDATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.UPDATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.UPDATE_TIME).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.CREATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.PAPER_FORM_ID).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.STATUS).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.NOTES).form().table().disable(true);

        cfg.view().field(HrTables.HR_PAPER.COST).form().validate().required();

        cfg.view().field(HrTables.HR_PAPER.CHOICE_SCORE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.JUDGE_SCORE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.RADIO_SCORE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.CREATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.TEXTAREA_SCORE).form().table().disable(true);

        cfg.view().field(HrTables.HR_PAPER.LEARN_ID).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.LEARN_PAPER_ID).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.RADIO_CNT).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.CHOICE_CNT).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.RADIO_SCORE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.JUDGE_CNT).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.TEXTAREA_CNT).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.LEARN_PAPER_ID).form().table().disable(true);

        cfg.view().field(HrTables.HR_PAPER.SDATE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.EDATE).form().table().disable(true);


        cfg.view().field(HrTables.HR_PAPER.CHOICE_SCORE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.JUDGE_SCORE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.RADIO_SCORE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.TEXTAREA_SCORE).form().table().disable(true);

        cfg.view().field(HrTables.HR_PAPER.SDATE).form().dateInput().defaultNow().type(DatePickerType.date);

        cfg.view().field(HrTables.HR_PAPER.COST).form().validate().required().form().numberInput().decimal().scale(1).defaultValue(30.0);
        cfg.view().field(HrTables.HR_PAPER.PASS_SCORE).form().validate().required().form().numberInput().decimal().scale(1).defaultValue(10.0);

        cfg.view().field(HrTables.HR_PAPER.CHOICE_SCORE).form().validate().required().form().numberInput().decimal().scale(1).defaultValue(2.0);
        cfg.view().field(HrTables.HR_PAPER.JUDGE_SCORE).form().validate().required().form().numberInput().decimal().scale(1).defaultValue(2.0);
        cfg.view().field(HrTables.HR_PAPER.RADIO_SCORE).form().validate().required().form().numberInput().decimal().scale(1).defaultValue(2.0);
        cfg.view().field(HrTables.HR_PAPER.TEXTAREA_SCORE).form().validate().required().form().numberInput().decimal().scale(1).defaultValue(2.0);

        cfg.view().field(HrTables.HR_PAPER.RADIO_CNT).form().validate().required().form().numberInput().integer().defaultValue(2);
        cfg.view().field(HrTables.HR_PAPER.CHOICE_CNT).form().validate().required().form().numberInput().integer().defaultValue(2);
        cfg.view().field(HrTables.HR_PAPER.JUDGE_CNT).form().validate().required().form().numberInput().integer().defaultValue(2);

        cfg.view().field(HrTables.HR_PAPER.TEXTAREA_CNT).form().validate().required().form().numberInput().integer().defaultValue(2);

        cfg.view().field(HrTables.HR_PAPER.MODE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.RAND_ENABLE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.FIX_ENABLE).form().table().disable(true);
        cfg.view().field(HrTables.HR_PAPER.SCORE_CONF).form().table().disable(true);


//        cfg.view().field(HrTables.HR_PAPER.NOTES).form().textArea().height(80);

//        cfg.view().field(HrTables.HR_PAPER.STATUS).form().validate().required().form()
//              .radioBox().enumType(StatusEnableEnum.class);

        cfg.view().field(HrTables.HR_PAPER.MODE).form().validate().required().form()
                .radioBox().enumType(PaperModeTypeEnum.class).defaultIndex(0);

        cfg.view().field(HrTables.HR_PAPER.SCORE_CONF).form().validate().required().form()
                .radioBox().enumType(PaperScoreTypeEnum.class).defaultIndex(0);
//
//        cfg.view().field(HrTables.HR_PAPER.RAND_ENABLE).form().validate().required().form()
//                .radioBox().enumType(StatusEnableEnum.class).defaultIndex(1);
//
//        cfg.view().field(HrTables.HR_PAPER.FIX_ENABLE).form().validate().required().form()
//                .radioBox().enumType(StatusEnableEnum.class).defaultIndex(0);

        cfg.view().field(HrTables.HR_PAPER.QUESTION_MODE).form().validate().required().form()
                .radioBox().enumType(PaperQuestionModeEnum.class).defaultIndex(0);


        cfg.view().field(HrTables.HR_PAPER.IF_LEARN).form().validate().required().form()
              .radioBox().enumType(YesNoEnum.class).defaultIndex(1);

        cfg.view().field(HrTables.HR_PAPER.LEARN_ID).form().validate().required().form().selectBox()
                .queryApi(LearnServiceProxy.QUERY_PAGED_LIST)
                .paging(true).filter(true).toolbar(false)
                .valueField(LearnMeta.ID).
                textField(LearnMeta.NAME).
                fillWith(PaperMeta.LEARN).muliti(false).defaultIndex(0);

        cfg.view().field(HrTables.HR_PAPER.LEARN_PAPER_ID).form().validate().required().form().selectBox()
                .queryApi(LearnPaperServiceProxy.QUERY_PAGED_LIST)
                .paging(true).filter(true).toolbar(false)
                .valueField(LearnPaperMeta.ID).
                textField(LearnPaperMeta.NAME).
                fillWith(PaperMeta.LEARN_PAPER).muliti(false).defaultIndex(0);



        cfg.view().search().labelWidth(1,Config.searchLabelWidth);
        cfg.view().search().labelWidth(2,Config.searchLabelWidth);
        cfg.view().search().labelWidth(3,Config.searchLabelWidth);
        cfg.view().search().labelWidth(4,Config.searchLabelWidth);
        cfg.view().search().inputWidth(Config.searchInputWidth);


        cfg.view().search().rowsDisplay(1);
        cfg.view().formWindow().width("80%");;
        cfg.view().formWindow().bottomSpace(150);



        cfg.view().form().addGroup(null,
                new Object[] {
                        HrTables.HR_PAPER.NAME,
                        HrTables.HR_PAPER.COST,
                        HrTables.HR_PAPER.QUESTION_MODE,
                        HrTables.HR_PAPER.MODE,
                },
                new Object[] {
                        HrTables.HR_PAPER.PASS_SCORE,
                        HrTables.HR_PAPER.SDATE,
                        HrTables.HR_PAPER.EDATE,

                }
        );
        cfg.view().form().addGroup("关联学习",
                new Object[] {
                        HrTables.HR_PAPER.IF_LEARN,
                },
                new Object[] {
                        HrTables.HR_PAPER.LEARN_ID,
                }
        );

        cfg.view().form().addGroup("得分配置",
                new Object[] {
                        HrTables.HR_PAPER.SCORE_CONF,
                }
        );
        cfg.view().form().addGroup(null,
                new Object[] {
                        HrTables.HR_PAPER.RADIO_SCORE,
                        HrTables.HR_PAPER.CHOICE_SCORE,
                },
                new Object[] {
                        HrTables.HR_PAPER.JUDGE_SCORE,
                        HrTables.HR_PAPER.TEXTAREA_SCORE,
                }
        );
        cfg.view().form().addGroup("抽题模式",
                new Object[] {
                        HrTables.HR_PAPER.LEARN_PAPER_ID,
                }
        );
        cfg.view().form().addGroup(null,
                new Object[] {
                        HrTables.HR_PAPER.RADIO_CNT,
                        HrTables.HR_PAPER.CHOICE_CNT,
                },
                new Object[] {
                        HrTables.HR_PAPER.JUDGE_CNT,
                        HrTables.HR_PAPER.TEXTAREA_CNT,
                }
        );



        cfg.view().form().addPage("questionList","题目列表","questionList");
        cfg.view().list().operationColumn().addActionButton("任务","release","release");
      // cfg.view().list().operationColumn().addActionButton("题目","question","question");
        cfg.view().list().operationColumn().addActionButton("预览","review","review");

        //文件生成覆盖模式
        cfg.overrides()
                .setServiceIntfAnfImpl(WriteMode.IGNORE) //服务与接口
                .setControllerAndAgent(WriteMode.IGNORE) //Rest
                .setPageController(WriteMode.IGNORE) //页面控制器
                .setBpmEventAdaptor(WriteMode.COVER_EXISTS_FILE)
                .setFormPage(WriteMode.COVER_EXISTS_FILE) //表单HTML页
                .setListPage(WriteMode.COVER_EXISTS_FILE) //列表HTML页
                .setExtendJsFile(WriteMode.WRITE_TEMP_FILE);
        //生成代码
        cfg.buildAll();
    }

    public static void main(String[] args) throws Exception {
        APaperGtr g=new APaperGtr();
        //生成代码
        g.generateCode();

        //移除之前生成的菜单，视情况执行
       // System.out.println("############"+g.getTablePrefix());
       // g.removeByBatchId("801716675761143808");
      //  //生成菜单
     //  g.generateMenu(PaperServiceProxy.class, PaperPageController.class);
    }
}
